package com.moon.game.command.guest.player;

import java.util.List;

import com.moon.game.clazz.PlayerItemsProto.PlayerItems.PlayerItem;
import com.moon.game.command.BaseCmd;
import com.moon.game.command.RequestSession;
import com.moon.game.exception.GException;
import com.moon.game.manager.LevelExpMG;
import com.moon.game.service.PlayerItemService;
import com.moon.game.vos.PlayerVo;

/**
 * @description 查看自己
 * @author Ranger 作者 E-mail:haozi000005@163.com
 * @version 创建时间：2012-5-24 上午10:59:25
 */
public class ViewSelfCmd extends BaseCmd{
	
	@Override
	protected void runOnce(RequestSession req) throws GException {
		switch (req.getStatus()) {
		case STATU_INIT:
			doInit(req);
			break;
		case STATU_CHECK:
			doCheckSelf(req);
			break;
		case STATU_RETURN:
			doResponse(req);
			break;
		default:
			break;
		}
	}

	@Override
	protected void doResponse(RequestSession req) throws GException {
		PlayerVo player = getPlayerVo(req);
		req.setVO(PAR_PLAYER_VO, player);
		req.setVO(PAR_FULL_EXP, LevelExpMG.instance.getLevelForExp(player.getLevel()));
		List<PlayerItem> items = PlayerItemService.getPlayerItems(player.getId());
		//人物属性
		int HotMinAttc = 0;
		int HotMaxAttc = 0;
		int ColdMinAttc = 0;
		int ColdMaxAttc = 0;
		int HotMinDec = 0;
		int HotMaxDec = 0;
		int ColdMinDec = 0;
		int ColdMaxDec = 0;
		//装备属性
		if (items != null) {
			for (PlayerItem playerItem : items) {
				if (!playerItem.getIsUse()) {
					continue;
				}
				if (playerItem.getAttackHotMin() > 0) {
					HotMinAttc += playerItem.getAttackHotMin();
				}
				if (playerItem.getAttackHotMax() > 0) {
					HotMaxAttc += playerItem.getAttackHotMax();
				}
				if (playerItem.getAttackColdMin() > 0) {
					ColdMinAttc += playerItem.getAttackColdMin();
				}
				if (playerItem.getAttackColdMax() > 0) {
					ColdMaxAttc += playerItem.getAttackColdMax();
				}
				if (playerItem.getDefenseHotMin() > 0) {
					HotMinDec += playerItem.getDefenseHotMin();
				}
				if (playerItem.getDefenseHotMax() > 0) {
					HotMaxDec += playerItem.getDefenseHotMax();
				}
				if (playerItem.getDefenseColdMin() > 0) {
					ColdMinDec += playerItem.getDefenseColdMin();
				}
				if (playerItem.getDefenseColdMax() > 0) {
					ColdMaxDec += playerItem.getDefenseColdMax();
				}
			}
		}
		//人物本身属性
		HotMaxAttc += player.getAttackHot();
		ColdMaxAttc += player.getAttackCold();
		HotMaxDec += player.getDefenseHot();
		ColdMaxDec += player.getDefenseCold();
		
		StringBuffer info = new StringBuffer();
		info.append("炎攻：" + HotMinAttc + "-" + HotMaxAttc + "<br/>");
		info.append("寒攻：" + ColdMinAttc + "-" + ColdMaxAttc + "<br/>");
		info.append("炎防：" + HotMinDec + "-" + HotMaxDec + "<br/>");
		info.append("寒防：" + ColdMinDec + "-" + ColdMaxDec + "<br/>");
		req.setVO(TAG_INFO, info);
		response(req, req.getClientResponse());
	}

}
